package com.shuang.controller;

import com.shuang.service.ExportService;
import com.shuang.service.ImportService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@RestController
public class SalariesController {

    @Resource
    private ExportService exportService;

    @Resource
    private ImportService importService;

    //方案一：查全表，写入一个sheet
    @GetMapping("export1")
    public void exportExcel1(HttpServletResponse response) throws IOException {
        exportService.exportExcel1(response);
    }

    //方案二：查全部，写入多个sheet
    @GetMapping("export2")
    public void exportExcel2(HttpServletResponse response) throws IOException {
        exportService.exportExcel2(response);
    }

    //方案三：分页查询，每页数据写入每个sheet  50秒
    @GetMapping("export3")
    public void exportExcel3(HttpServletResponse response) throws IOException {
        exportService.exportExcel3(response);
    }

    //方案四：多线程分页查询，每页数据写入多个sheet
    @GetMapping("export4")
    public void exportExcel4(HttpServletResponse response) throws IOException, InterruptedException {
        exportService.exportExcel4(response);
    }

    //excel的导入
    @PostMapping("import")
    public void importExcel(MultipartFile file) throws IOException {
        //同步导入（方案一、方案二-单线程解析）
//        importService.importExcel(file);
        //异步导入（方案三、方案四-多线程解析）
        importService.importExcelAsync(file);
    }
}